package com.banana.manager.forest.service.impl.handle;

import com.banana.manager.forest.dao.handle.IAreaDao;
import com.banana.manager.forest.entity.handle.AreaBean;
import com.banana.manager.forest.service.iihandle.IAreaService;
import com.banana.manager.forest.util.PageInfoSize;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class AreaServiceImpl implements IAreaService {
    @Resource
    private IAreaDao areaDao;

    @Override
    public AreaBean addNewArea(AreaBean areaBean) {
        areaDao.insert(areaBean);
        return areaDao.selectById(areaBean.getAreaId());
    }

    @Override
    public PageInfo<AreaBean> findBlurByPage(Integer page, String areaName, String areaWoods, String className) {
        QueryWrapper<AreaBean> queryWrapper = new QueryWrapper<>();
        areaName = "%"+areaName+"%";
        areaWoods = "%"+areaWoods+"%";
        PageHelper.startPage(page, PageInfoSize.pageSize);
        return PageInfo.of(areaDao.getAreaIncludeClass(areaName,areaWoods,className));
    }

    @Override
    public List<AreaBean> findNoClassArea() {
        return areaDao.getNoClassAreaBean();
    }

    @Override
    public AreaBean findClassByAreaName(String areaName) {
        return areaDao.getClassByAreaName(areaName);
    }
}
